from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Member(models.Model):
    member = models.ForeignKey(User, related_name = 'member_user')
    lastLoginTime = models.DateTimeField(auto_now_add = True)
    entryCount = models.IntegerField(default = 0)
    commentCount = models.IntegerField(default = 0)
    motto = models.CharField(max_length = 255)

    def __unicode__(self):
        return self.User.username

class Message(models.Model):
    member = models.ForeignKey(Member, related_name = 'message_user')
    createdTime = models.DateTimeField(auto_now_add = True)
    content = models.TextField()
    isRead = models.BooleanField(default = False)

    def __unicode__(self):
        return self.id

class Category(models.Model):
    name = models.CharField(max_length = 75)
    entryCount = models.IntegerField(default = 0)

    def __unicode__(self):
        return self.name

class Tag(models.Model):
    name = models.CharField(max_length = 75)
    entryCount = models.IntegerField(default = 0)

    def __unicode__(self):
        return self.name

class Entry(models.Model):
    name = models.CharField(max_length = 255)
    member = models.ForeignKey(Member, related_name = 'entry_user')
    category = models.ForeignKey(Category)
    commentCount = models.IntegerField(default = 0)
    tags = models.ManyToManyField(Tag)

    def __unicode__(self):
        return self.name

class Comment(models.Model):
    member = models.ForeignKey(Member, related_name = 'comment_user')
    entry = models.ForeignKey(Entry)
    content = models.TextField()
    good = models.IntegerField(default = 0)
    bad = models.IntegerField(default = 0)
    isBest = models.BooleanField(default = False)
    createdTime = models.DateTimeField(auto_now_add = True)
    modifiedTime = models.DateTimeField(auto_now = True)

    def __unicode__(self):
        return self.entry.name + '-' + self.member.user.username
